//package com.fire.filter;
//
//import java.io.IOException;
//
//import javax.servlet.Filter;
//import javax.servlet.FilterChain;
//import javax.servlet.FilterConfig;
//import javax.servlet.ServletException;
//import javax.servlet.ServletRequest;
//import javax.servlet.ServletResponse;
//import javax.servlet.annotation.WebFilter;
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import javax.servlet.http.HttpSession;
//
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import com.sowell.sjzt.configuration.WhiteListConfig;
//import com.sowell.sjzt.listener.MySessionContext;
//import com.sowell.sjzt.util.basicUtils.BooleanUtil;
//
//@Component
//@WebFilter(filterName = "loginFilter", urlPatterns = "/*")
//public class LoginFilter implements Filter {
//
//	@Autowired
//	private WhiteListConfig whiteList;
//
//	@Override
//	public void init(FilterConfig filterConfig) throws ServletException {
//
//	}
//
//	@Override
//	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
//			throws IOException, ServletException {
//		// 设置请求编码格式
//		request.setCharacterEncoding("UTF-8");
//
//		HttpServletRequest requ = (HttpServletRequest) request;
//		HttpServletResponse resp = (HttpServletResponse) response;
//		// 获取请求路径
//		String servletPath = requ.getServletPath();
//		
//		resp.setHeader("testCookie", requ.getSession().getId());
//		
// 		String sessionId = requ.getHeader("testCookie");
//		
//		if(sessionId == null || "".equals(sessionId)) {
//			sessionId = request.getParameter("testCookie");
//		}
//		
//		if (BooleanUtil.StringIsNa(sessionId)) {
//			sessionId = sessionId.substring(1, sessionId.length() - 1);
//		}
//		if (!isRightSession(sessionId) && !whiteList.getWhiteList().contains(servletPath)) {
//			requ.getRequestDispatcher(requ.getContextPath() + "/userController/noLoginIn.do").forward(requ, resp);
//			return;
//		}
// 		chain.doFilter(requ, resp);
//	}
//	
//	@Override
//	public void destroy() {
//
//	}
//
//	private boolean isRightSession(String sessionId) {
//		HttpSession session = MySessionContext.getSession(sessionId);
//		return null != sessionId && null != session;
//	}
//
//}
